package com.ioftv.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ioftv.entity.ProjectPackage;
import com.ioftv.mapper.ProjectPackageMapper;
import com.ioftv.service.ProjectPackageService;
import com.ioftv.service.base.BaseService;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

/**
 * 项目总览Service实现类
 */
@Service
public class ProjectPackageServiceImpl extends BaseService<ProjectPackageMapper, ProjectPackage> implements ProjectPackageService {

    @Override
    public ProjectPackage getByStatDate(LocalDate statDate) {
        LambdaQueryWrapper<ProjectPackage> queryWrapper = createUserQueryWrapper();
        queryWrapper.eq(ProjectPackage::getStatDate, statDate);
        return this.getOne(queryWrapper);
    }
    
    @Override
    public ProjectPackage getByStatDateAndUserId(LocalDate statDate, Long userId) {
        LambdaQueryWrapper<ProjectPackage> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ProjectPackage::getStatDate, statDate);
        queryWrapper.eq(ProjectPackage::getUserId, userId);
        return this.getOne(queryWrapper);
    }

    @Override
    protected void addUserCondition(LambdaQueryWrapper<ProjectPackage> queryWrapper) {
        queryWrapper.eq(ProjectPackage::getUserId, getCurrentUserId());
    }

    @Override
    protected void setEntityUserId(ProjectPackage entity) {
        if (entity.getUserId() == null) {
            entity.setUserId(getCurrentUserId());
        }
    }
}